package com.loiot.baqi.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;

import org.json.simple.JSONObject;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.loiot.baqi.dao.TgProductSettingDao;

/**
 * 建议 逻辑类。
 * 
 * @author Hinsteny
 * @creation 2016-03-07
 */
@Service("tgProductSettingService")
@Transactional
public class TgProductSettingService {

	// private Logger log = LoggerFactory.getLogger(this.getClass());

	@Resource
	private TgProductSettingDao tgProductSettingDao;

	/**
	 * 查询 礼品设置列表(全信息)
	 * 
	 * @return 礼品设置列表
	 */
	@SuppressWarnings("unchecked")
	public JSONObject getSetProductGiftInfoList(HashMap<String, Object> pMap) throws Exception {

		HashMap<Long, HashMap<String, Object>> lunBoGifttMap = new HashMap<Long, HashMap<String, Object>>();
		List<HashMap<String, Object>> lunBoGiftList = new ArrayList<HashMap<String, Object>>();

		// 获取礼品
		List<HashMap<String, Object>> giftList = tgProductSettingDao.getSetProductGiftInfoList(pMap);
		for (HashMap<String, Object> giftInfo : giftList) {
			long productId = (long) giftInfo.get("product_id");
			if (!lunBoGifttMap.containsKey(productId)) {
				lunBoGifttMap.put(productId, giftInfo);
				lunBoGiftList.add(giftInfo);
			}
		}

		JSONObject obj = new JSONObject();
		obj.put("giftList", giftList);
		obj.put("lunBoGiftList", lunBoGiftList);

		return obj;
	}
}
